package cn.bdqn.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bdqn.entity.Comment;
import cn.bdqn.entity.CommentVO;
import cn.bdqn.entity.UsersAndComVo;
import cn.bdqn.service.CommentService;
import cn.bdqn.service.ComplaintsService;

@Controller
@RequestMapping("comment")
public class CommentController {
	@Autowired
	private CommentService service;
	@Autowired
	private ComplaintsService comservice;
	@RequestMapping("queryAllComment")
	public String queryAllComment(Integer complaintsid,Model model) {
		UsersAndComVo complaints=comservice.queryComplaintsbyComplaintsid(complaintsid);
		List<CommentVO> list=service.queryAllCommentByComplaintsId(complaintsid);
		model.addAttribute("com", complaints);
		model.addAttribute("list", list);
		return "detailcomment";
	}
	@RequestMapping("saveComment")
	public String saveComment(Comment comment) {
		Integer count=service.saveComment(comment);
		return "forward:/comment/queryAllComment?complaintsid="+comment.getComment_complainid();
	}
	@RequestMapping("deleteComment")
	public String deleteComment(Integer commentid,Integer complaintsid) {
		Integer num=service.deleteComment(commentid);
		System.out.println("删除："+num);
		return "forward:/comment/queryAllComment?complaintsid="+complaintsid;
	}
}
